package guowei.gulicart.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 自定义可编程式线程池  用于得到商品详细信息时 改为异步编排
 */
@Configuration
public class MyselfThreadPoolConfig {

    @Bean
    public ThreadPoolExecutor getExecutor(ThreadPoolConfiguration configuration){
        ThreadPoolExecutor executor1 = new ThreadPoolExecutor(configuration.getCoreThread(),
                configuration.getMaxThread(),
                configuration.getKeepTime(),
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(10000),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());
        return executor1;
    }
}
